package com.sc.nft.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.SaasTaskAddDTO;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.*;
import com.sc.nft.service.SaasTaskAwardDetailsService;
import com.sc.nft.service.SaasTaskService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * 任务基础表(SaasTask)表控制层
 *
 * @author 王伟成
 * @since 2024-01-11 15:15:23
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/saasTask")
@Api(tags = "任务管理")
public class SaasTaskController {
    /**
     * 服务对象
     */
    private final SaasTaskService saasTaskService;

    private final SaasTaskAwardDetailsService saasTaskAwardDetailsService;

    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "任务基础列表", notes = "任务基础列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<SaasTaskBasicsVO> page(@RequestBody SaasTaskBasicsDTO saasTaskBasicsDTO) {
        IPage<SaasTaskBasicsVO> page = saasTaskService.pageBasics(saasTaskBasicsDTO);
        return PageResult.success(page);
    }

    @PostMapping(value = "/pageStar", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "星球任务基础列表", notes = "星球任务基础列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<SaasTaskBasicsVO> pageStar(@RequestBody SaasTaskBasicsDTO saasTaskBasicsDTO) {
        IPage<SaasTaskBasicsVO> page = saasTaskService.pageStar(saasTaskBasicsDTO);
        return PageResult.success(page);
    }

    @PostMapping(value = "/getByIdDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "根据id获取详情", notes = "任务基础列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<SaasTaskDetailsVO> getByIdDetails(@RequestBody IdRequest idRequest) {
        return Result.success(saasTaskService.getByIdDetails(idRequest.getId()));
    }

    @PostMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取奖励列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<SaasTaskAwardDetailsListVO> list(@Valid @RequestBody SaasTaskAwardDetailsListDTO saasTaskAwardDetailsListDTO) {
        return Result.success(saasTaskAwardDetailsService.list(saasTaskAwardDetailsListDTO));
    }


    @PostMapping(value = "audit", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "审核", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result audit(@RequestBody SaasTaskAuditDTO saasTaskAuditDTO) {
        saasTaskAwardDetailsService.audit(saasTaskAuditDTO);
        return Result.success();
    }

    @PostMapping(value = "modification", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result modification(@RequestBody SaasTaskModificationDTO saasTaskModificationDTO) {
        saasTaskAwardDetailsService.modification(saasTaskModificationDTO);
        return Result.success();
    }


    @PostMapping(value = "add", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增任务基础数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result add(@Valid @RequestBody SaasTaskAddDTO saasTaskAddDTO) {
        saasTaskService.add(saasTaskAddDTO);
        return Result.success();
    }

    @PostMapping(value = "modificationStar", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改星球任务", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result modification(@Valid @RequestBody SaasTaskModificationStarDTO saasTaskModificationStarDTO) {
        saasTaskService.modificationStar(saasTaskModificationStarDTO);
        return Result.success();
    }


    @PostMapping(value = "taskType", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "任务类型", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Map> taskType() {
        return Result.success(saasTaskService.taskType());
    }


    @PostMapping(value = "startOrEnd", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "启动或关闭", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result startOrEnd(@Valid @RequestBody SaasTaskStartOrEndDTO saasTaskStartOrEndDTO) {
        saasTaskService.startOrEnd(saasTaskStartOrEndDTO);
        return Result.success();
    }

    @PostMapping(value = "submitAudit", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "提交审核", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result submitAudit(@RequestBody IdRequest idRequest) {
        saasTaskService.submitAudit(idRequest.getId());
        return Result.success();
    }

    @PostMapping(value = "revocation", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "撤销审核", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result revocation(@RequestBody IdRequest idRequest) {
        saasTaskService.revocation(idRequest.getId());
        return Result.success();
    }
}
